<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="隐患名称" prop="htName">
        <el-input v-model="queryParams.htName" placeholder="请输入隐患名称" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="状态" prop="states">
        <el-radio-group v-model="queryParams.states">
          <el-radio label="3">待验收</el-radio>
          <el-radio label="4">已验收</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 操作工具栏 -->
    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <!-- 列表 -->
    <el-table v-loading="loading" :data="list" stripe>
      <!--<el-table-column label="主键" align="center" prop="id" />-->
      <el-table-column label="序号" type="index" width="50" />
      <el-table-column label="隐患名称" align="center" prop="htName" />
      <el-table-column label="检查日期" align="center" prop="checkDate" width="150">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.checkDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="检查人" align="center" prop="checkPeo">
        <!--        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_LEVEL" :value="scope.row.level" />
        </template> -->
      </el-table-column>
      <el-table-column label="隐患等级" align="center" prop="level">
        <template slot-scope="scope">
          <dict-tag :type="DICT_TYPE.HT_LEVEL" :value="scope.row.level" />
        </template>
      </el-table-column>
      <el-table-column label="所属单位" align="center" prop="beCheckDept" />
      <el-table-column label="隐患描述" align="center" prop="description">
      </el-table-column>
      <el-table-column label="隐患状态" align="center" prop="state">
        <template slot-scope="scope">
          <el-button type="text" size="mini">
            <dict-tag :type="DICT_TYPE.HT_STATE" :value="scope.row.state" />
          </el-button>
        </template>
      </el-table-column>
      <el-table-column label="整改方式" align="center" prop="rectificationType">
        <template slot-scope="scope">
          <span v-if="scope.row.rectificationType==0">立即整改</span>
          <span v-if="scope.row.rectificationType==1">限期整改</span>
        </template>
      </el-table-column>
      <el-table-column label="整改期限" width="150" align="center" prop="rectificationLimit">
        <template slot-scope="scope">
          {{ parseTime(scope.row.rectificationLimit, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <el-table-column label="延期日期" width="150" align="center" prop="deferDate">
        <template slot-scope="scope">
          <span style="color: #E6A23C;">{{ parseTime(scope.row.deferDate, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="整改完成日期" width="150" align="center" prop="rectificationDate">
        <template slot-scope="scope">
          {{ parseTime(scope.row.rectificationDate, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <el-table-column label="整改责任人" align="center" prop="rectificationPeo">
      </el-table-column>
      <el-table-column label="整改责任单位" align="center" prop="rectificationDept">
      </el-table-column>

      <el-table-column label="操作" width="150" fixed="right" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleDetail(scope.row)" v-if="scope.row.state=='3'">验收</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- 验收弹窗 -->
    <el-dialog title="隐患验收" :visible.sync="openDetail" width="700px" append-to-body>
      <el-form ref="form" :model="form" label-width="90px" :rules="rules" class="detail">
        <el-descriptions class="margin-top" :column="2" border>
          <el-descriptions-item>
            <template slot="label">
              隐患名称
            </template>
            {{form.htName}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              隐患等级
            </template>
            <dict-tag :type="DICT_TYPE.HT_LEVEL" :value="form.level" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              隐患描述
            </template>
            {{form.description}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              检查类型
            </template>
            <dict-tag :type="DICT_TYPE.CHECK_TYPE" :value="form.checkType" />
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              隐患地点
            </template>
            {{form.place}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              检查人
            </template>
            {{form.checkPeo}}
            </el-select>
          </el-descriptions-item>
          <!-- <el-descriptions-item>
            <template slot="label">
              所属风险点
            </template>
            {{form.checkPeoId}}
          </el-descriptions-item> -->
          <el-descriptions-item>
            <template slot="label">
              所属单位
            </template>
            {{form.checkDept}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改方式
            </template>
            {{form.rectificationType==0?'立即整改':'限期整改'}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改责任人
            </template>
            {{form.rectificationPeo}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改责任单位
            </template>
            {{form.rectificationDept}}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改期限
            </template>
            {{ parseTime(form.rectificationLimit, "{y}-{m}-{d}") }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改完成时间
            </template>
            {{ parseTime(form.rectificationDate, "{y}-{m}-{d}") }}
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改前
            </template>
            <el-image v-for="item in form.ossImg" style="width: 100px; height: 100px;" :src="item.url"  :preview-src-list="[item.url]"/>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改后
            </template>
            <el-image v-for="item in form.rectificationOssImg" style="width: 100px; height: 100px;" :src="item.url"  :preview-src-list="[item.url]"/>
          </el-descriptions-item>
          <el-descriptions-item>
            <template slot="label">
              整改结果
            </template>
            {{form.rectificationResult}}
             </el-descriptions-item>
        </el-descriptions>
        <el-row>
          <el-col :span="24">
            <el-form-item>
              <el-radio-group v-model="reject1" @change="changeIssue">
                <el-radio label="1">同意</el-radio>
                <el-radio label="2">拒绝</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="24" v-if="reject1==2">
            <el-form-item label="驳回原因:" prop="level">
              <el-input type="textarea" v-model="cancelInfo" :rows="3" placeholder="请输入驳回原因"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="reject1==1" @click="confirmRecification" type="primary">同意</el-button>
        <el-button v-if="reject1==2" type="warning" @click="reject">驳回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import ElRow from "element-ui/packages/row/src/row";
  import {
    updateHtHiddentroubleCancel,
    getHtHiddentroubleCancel,
    getHtHiddenIssueCancelpage
  } from "@/api/biz/htHiddenCheck";
  export default {
    name: "HtHiddentrouble",
    components: {
      ElRow
    },
    data() {
      return {
        reject1: '',
        // 遮罩层
        loading: false,
        showReject: false,
        // 导出遮罩层
        exportLoading: false,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 隐患信息列表
        list: [{
          htName: '1'
        }],
        // 弹出层标题
        title: "隐患整改",
        // 是否显示弹出层
        open: false,
        cancelInfo: '',
        openDetail: false,
        dateRangeCheckDate: [],
        // 查询参数
        queryParams: {
          pageNo: 1,
          pageSize: 10,
          states:'3'
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          htName: [{
            required: true,
            message: "隐患名称不能为空",
            trigger: "blur"
          }],
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNo = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      changeIssue(e) {
        this.reject1 = e
      },
      /** 查询列表 */
      getList() {
        this.loading = true;
        // 处理查询参数
        let params = {
          ...this.queryParams
        };
        // this.addBeginAndEndTime(params, this.dateRangeCheckDate, 'checkDate');
        // 执行查询
        getHtHiddenIssueCancelpage(params).then(response => {
          this.list = response.data.list;
          this.total = response.data.total;
          this.loading = false;
        });
      },
      // 隐患验收
      handleDetail(row) {
        this.title = "隐患验收"
        const id = row.id;
        this.reject1 = '';
        this.cancelInfo = ''
        getHtHiddentroubleCancel(id).then(response => {
          this.form = response.data;
          this.openDetail = true
          this.showReject = false
        });

      },
      //确认验收
      confirmRecification() {
        var that = this;

        if (this.form.id != null) {
          var query = {
            id: that.form.id,
            htId:that.form.htId,
            cancelResult: '同意'
          }
          updateHtHiddentroubleCancel(query).then(response => {
            this.$modal.msgSuccess("操作成功");
            this.openDetail = false
            this.getList();
          });
        }
      },
      reject() { //驳回
        var that = this;
        if (!this.cancelInfo) {
          this.$message.error('请输入驳回原因');
          return
        } else {
          var query = {
            id: that.form.id,
            htId:that.form.htId,
            cancelResult: '拒绝',
            cancelInfo:that.cancelInfo
          }
          updateHtHiddentroubleCancel(query).then(response => {
            that.$modal.msgSuccess("操作成功");
            that.openDetail = false
            that.getList();
          });
        }
      },
      /** 取消按钮 */
      cancel() {
        this.open = false;
      },
      // cancelDetail() {
      //   this.openDetail = false;
      // },

      /** 提交按钮 */
      submitForm() {
        this.open = false
      },
      handleRemove(file, fileList) {
        console.log(file, fileList);
      },
      handlePreview(file) {
        console.log(file);
      },
      handleExceed(files, fileList) {
        this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
      },
      beforeRemove(file, fileList) {
        return this.$confirm(`确定移除 ${ file.name }？`);
      }
    }
  };
</script>
<style scoped>
  /deep/ .el-input--medium .el-input__inner {
    border: none;
  }

  /deep/ .detail .el-col-12 {
    border: 0.5px solid #e9e9e9;
  }

  /deep/ .el-form-item {
    margin: 5px 10px;
  }
</style>
